package com.ror.java.se.io;

/*
    练习：更大文件拷贝（每次拷贝一个字节数组）
 */

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Demo04BigCopy {
    public static void main(String[] args) throws IOException {
        long before = System.currentTimeMillis();
        File src = new File("assets/io/byte/java-poker-game.mp4");
        File dest = new File("assets/io/byte/copy.mp4");
        FileInputStream fi = new FileInputStream(src);
        FileOutputStream fo = new FileOutputStream(dest);
        int len; //每次读的长度
        byte[] buffer = new byte[1024 * 1024 * 5]; //每次尽可能读5MiB
        while ((len = fi.read(buffer)) != -1) {
            fo.write(buffer, 0, len);
        }
        fo.close();
        fi.close();
        long after = System.currentTimeMillis();
        System.out.println(after - before + "ms took.");
//        dest.delete();
    }
}
